package com.woniuxy.yygh.hsop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.yygh.common.exception.YyghException;
import com.woniuxy.yygh.common.result.ResultCodeEnum;
import com.woniuxy.yygh.hsop.mapper.HospitalSetMapper;
import com.woniuxy.yygh.hsop.service.HospitalSetService;
import com.woniuxy.yygh.model.hosp.HospitalSet;
import com.woniuxy.yygh.vo.order.SignInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 医院实现类
 * <P> Date: 2022/2/27:13:51
 * <P> Description:
 */
@Service
public class HospitalSetServiceImpl
        extends ServiceImpl<HospitalSetMapper, HospitalSet>
        implements HospitalSetService {
    //ServiceImpl 已经实现了mapper自动注入

    /**
        * TODO:通过hoscode 医院编号 获得签名秘钥 SingKey
    **/
    @Override
    public String getSingKey(String hoscode) {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);

        return hospitalSet.getSignKey();
    }

    /**
     * TODO:根据医院编号获取医院签名信息
     **/
    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        //医院编号
        wrapper.eq("hoscode",hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);

        if(null == hospitalSet) {
            throw new YyghException(ResultCodeEnum.HOSPITAL_OPEN);
        }
        //签名信息
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        return signInfoVo;
    }
}
